﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp13
{
    class Program
    {
       static Student student1 = new Student(1, "张三", 23);
       static Student student2 = new Student(2, "李四", 20);
       static Student student3 = new Student(3, "王五", 21);
       static Student student4 = new Student(4, "赵六", 19);
       static Student student5 = new Student(5, "胡七", 18);
       static Hashtable ht = new Hashtable();
       static List<Student> arrayList = new List<Student>();
      
    
 
        static void Main(string[] args)
        {
            arrayList.Add(student1);
            arrayList.Add(student2);
            arrayList.Add(student3);
            arrayList.Add(student4);
            arrayList.Add(student5);
            ht.Add(student1.Num, student1);
            ht.Add(student2.Num, student2);
            ht.Add(student3.Num, student3);
            ht.Add(student4.Num, student4);
            ht.Add(student5.Num, student5);

            inquire1();
        }
       
        public static void inquire1()
        {
            Console.WriteLine("请选择你的功能：1、添加学生信息。2、查询学生信息。");
            string key = Console.ReadLine();
            switch (key)
            {
                case "1":
                    Console.WriteLine("请输入学生学号");
                    int num = int.Parse(Console.ReadLine());
                    Console.WriteLine("请输入学生的姓名");
                    string name = Console.ReadLine();
                    Console.WriteLine("请输入学生的年龄");
                    int age = int.Parse(Console.ReadLine());
                    Student student = new Student(num,name,age);
                    
                    //Console.WriteLine("学号已经存在重新输入");
                    ////inquire1();
                    if (ht.Contains(num))
                    {
                        Console.WriteLine("学号已经存在重新输入");
                        inquire1();
                    }
                    else
                    {
                        ht.Add(student.Num, student);
                        arrayList.Add(student);
                        Console.WriteLine("添加成功，按任意键返回上一级");
                        inquire1();
                    }
                   
 
                    Console.ReadKey();
                    
                    break;
                case "2":
                    inquire2();
                    break;
                default:
                    break;
            }
        }
        
        public static void inquire2()
        {
            Console.WriteLine("请输入你要的功能:1、查询所有（按学号排序）、2、查询所有（按姓名排序）、3、查询所有（按年龄排序）、按学号查询（查没有，则打印查无此学生）、5、退出");
            string key = Console.ReadLine();
            switch (key)
            {
                case "1"://1、查询所有（按学号排序）
                    Console.WriteLine("查询所有（按学号排序）");
                    
                    foreach (var item in arrayList)
                    {
                        Console.WriteLine(item);
                    }
                    inquire1();
                    break;
                case "2"://2、查询所有（按姓名排序）
                    Console.WriteLine("查询所有（按姓名排序）");
                    arrayList.Sort(new NameSort());
                    foreach (var item in arrayList)
                    {
                        Console.WriteLine(item);
                    }
                    inquire1();
                    break;
                case "3"://3、查询所有（按年龄排序）
                    Console.WriteLine("查询所有（按年龄排序）");
                    arrayList.Sort(new AgeSort());
                    foreach (var item in arrayList)
                    {
                        Console.WriteLine(item);
                    }
                    inquire1();
                    break;
                case "4"://按学号查询（查没有，则打印查无此学生）
                    Console.WriteLine("请输入你要查询的学生信息的学号");
                    int a = int.Parse(Console.ReadLine());

                        if (ht.Contains(a))
                        {
                            
                            Console.WriteLine("该学生存在");
                            Console.WriteLine();
                            
                        }
                        else
                        {
                            Console.WriteLine("查无此学生");
                        }
                    



                    inquire1();
                    break;
                case "5"://5、退出

                    Environment.Exit(0);
                    break;

                default:
                    Console.ReadKey(true);
                    break;
                   
            }
        }
    }
}
